﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace BookStore.Models
{
    public class ShippingDetailMethodModel
    {
        private string connectionString;
        private SqlConnection connect;

        public ShippingDetailMethodModel()
        {
            connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            connect = new SqlConnection(connectionString);
        }
        public void InsertDetailShipping(string[] data)
        {
            connect.Open();
            string selectSQL;
            selectSQL = "INSERT INTO Shipping_detail (shipping_id,name,address,phone,email) VALUES (N'" + data[0] +"',N'" + data[1] + "',N'" + data[2] + "',N'" + data[3] + "',N'" + data[4] + "')";
            SqlCommand cmd = new SqlCommand(selectSQL, connect);
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public string getLastId()
        {
            string ID = "";
            connect.Open();
            string selectSQL = "SELECT max(shipping_detail_id) FROM Shipping_detail ";
            SqlCommand cmd = new SqlCommand(selectSQL, connect);
            SqlDataReader reader;
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                ID = reader[0].ToString();
            }
            connect.Close();
            return ID;
        }
    }
       
}
